13 of 14

Choosing a Client State Management Method
As is the case with any application development, it's important to understand the adverse consequences of creating an application without carefully considering what the final production environment may be in the future.

In my view nothing drives this point home more clearly than the decision of whether to use client or session variables when creating a new CF application. If you create an entire application using session variables and suddenly it's brought to everyone's attention that the site is going to run in a load-balanced environment, you'll have a lot of rewriting and testing to do. Discussion of the final production environment during the planning phase of an application can help avoid that situation. It seems like a no-brainer, but warrants emphasis: it's a lot easier to build the application from the ground up to support the environment it will be running under, rather than rebuild it later.

If it's determined that your application will never need to run in a load-balanced/clustered environment, then you'll probably lean more towards using session variables - you can bet that I do. The primary advantage that I can see in using session variables is lower database overhead. That's really the only major downfall of client variables - the need to access a database to use them. However, the stored procedure code I have provided in this article has made my own company's solutions very efficient and we've seen no degradation in performance. To paraphrase the philosophy of a great ColdFusion guru (thanks, Ben!): "It is scalable - it's all in how you code."

An added benefit of storing those client variables in the database is that now they are available via standard queries, for reporting - I have even written a routine into one application that will kill users' sessions and disable their accounts with one click of a mouse should they be "misbehaving." Client variables make this and other user management and session reporting very easy.

If you're expecting high traffic on your site or application, then you're already planning (or should be!) for some sort of load balancing to meet the demand. With good code, good clustering software, the right hardware and perhaps a clustered database server configuration, wrapping things up with good client state management will guarantee a good user experience with exceptional fault tolerance should anything go awry.

13 of 14